#include "mainwindow.h"

#include <phonon/mediaobject.h>
#include <phonon/MediaObject>
#include <QDebug>
#include <QPainter>
#include <QPixmap>
#include <QPalette>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    ui = new QDeclarativeView(this);
    ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    ui->setAttribute(Qt::WA_TranslucentBackground);
    ui->setStyleSheet("background:transparent;");
    ui->setSource(QUrl::fromLocalFile("/socMDC/KdeadMouse/apps/youtube/qml/main.qml"));

    Phonon::MediaObject* media = new Phonon::MediaObject();
    media->setCurrentSource(Phonon::MediaSource(QString("/home/manu/4Ms6i4rP-LY.flv")));//uVSk_WDI-yY.mp4
    //videoWidget = new Phonon::VideoWidget(this);


    videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory);
    this->resize(500,400);
    videoPlayer->resize(500,400);
    //videoPlayer->resize(this->size());
    //



    //ui->scene()->addWidget(videoPlayer);
    //this->setCentralWidget(videoPlayer);
    this->setCentralWidget(ui);

    videoPlayer->play(media->currentSource());
    videoWidget = videoPlayer->videoWidget();
    //media->play();
    qDebug()<< "after play";
    videoPlayer->show();

}

void MainWindow::focusInEvent(QFocusEvent *e){
    qDebug()<<"top focusInEvent";

}

void MainWindow::paintEvent(QPaintEvent* e){
    /*QPixmap pixmap;
    pixmap.load("/home/manu/Images/asse2.jpg");
    pixmap = QPixmap::fromImage(videoWidget->snapshot());

    QPainter paint(this);
    //paint.drawImage(0, 0,videoWidget->snapshot());
    paint.drawPixmap(0,0,pixmap);
    QWidget::paintEvent(e);
    update();

    */

    QPalette palette;
    palette.setBrush(this->backgroundRole(), QBrush(videoWidget->snapshot()));
    this->setPalette(palette);

}



MainWindow::~MainWindow()
{
    delete videoPlayer;
}
